from glob import glob
import os.path as osp
from tqdm import tqdm
import shutil
import os
from util.dir_util import makesureDir


if __name__ == '__main__':
    base_path = r"G:\不同部位数据集\腹部\腹部-未知"
    save_path = r"G:\不同部位数据集\temp"

    makesureDir(save_path)

    # all_files = set(glob(osp.join(base_path, "*")))
    all_iq_files = glob(osp.join(base_path, "**", "*.iq"), recursive=True)
    all_raw_files = glob(osp.join(base_path, "**", "*.raw"), recursive=True)

    all_iq_name = [file_path.split(".iq")[0] for file_path in all_iq_files]
    all_raw_name = [file_path.split(".raw")[0] for file_path in all_raw_files]
    usefull_name_list = list(set(all_iq_name).intersection(set(all_raw_name)))

    for name in tqdm(usefull_name_list):
        if "refImage" in name:
            continue
        png_path = f"{name}.png"
        raw_path = f"{name}.raw"
        iq_path = f"{name}.iq"
        rel_path = osp.dirname(osp.relpath(raw_path, base_path))
        result_save_path = osp.join(save_path, rel_path)
        makesureDir(result_save_path)
        if osp.exists(png_path):
            shutil.move(png_path, result_save_path)
        if osp.exists(raw_path):
            shutil.move(raw_path, result_save_path)
        if osp.exists(iq_path):
            shutil.move(iq_path, result_save_path)



